package com.example.arithmeticleetcode.learnArithmetic2.union;

/**
 * @program: arithmetic-leetcode
 * @description: 基于rank进行优化--路径压缩
 * @author: FangZhen
 * @create: 2020-11-12 18:44
 **/
public class UnionFind_QU_R_PC extends UnionFind_QU_R {


    public UnionFind_QU_R_PC(int capacity) {
        super(capacity);
    }

    /**
     * @param v O(logN)
     * @return
     */
    @Override
    public int find(int v) {
        rangeCheck(v);
        if (parents[v] != v) {
            parents[v] = find(parents[v]);
        }
        return parents[v];
    }
}
